package com.czh.gzskzn.qqkonjian.DaKaFagment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.TextureMapView;
import com.baidu.mapapi.model.LatLng;
import com.czh.gzskzn.qqkonjian.MainActivity;
import com.czh.gzskzn.qqkonjian.R;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.czh.gzskzn.qqkonjian.R.id.textView;

/**
 * Created by gzsk on 2017/5/9.
 * name  陈忠红
 * email czhhx15599109256@163.com
 */

public class DakaFragment extends Fragment implements Runnable {

    private View view;

    private TextView shiJian, tvDaKa;
    private Handler handler;
    private LinearLayout buJu;
    public TextureMapView mMapView;
    public BaiduMap baiduMap;
    private Marker mMarkerB;
    double mCurrentLantitude = 0.0;
    double mCurrentLongitude = 0.0;
    private CheckBox animationBox = null;
    // 定位相关声明
    public LocationClient locationClient = null;
    //自定义图标
    BitmapDescriptor mCurrentMarker = null;
    BitmapDescriptor mCurrentMarker1 = null;
    BaiduMap.OnMarkerClickListener listener;
    boolean isFirstLoc = true;// 是否首次定位


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.daka_fagment, container, false);
        intiView();
        xianShi();
        dianJie();

        return view;
    }





    private void dianJie() {

        buJu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop_up();
            }
        });

    }

    private void xianShi() {

        handler = new Handler() {
            public void handleMessage(Message msg) {
                shiJian.setText((String)msg.obj);
            }
        };

        new Thread(this).start();
    }

    private void intiView() {
        shiJian = (TextView) view.findViewById(R.id.daka_shijian);
        buJu = (LinearLayout) view.findViewById(R.id.buju_daka);
        tvDaKa = (TextView) view.findViewById(R.id.tv_daka);
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        try {
            while(true){
                SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
                String str=sdf.format(new Date());
                handler.sendMessage(handler.obtainMessage(100,str));
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void pop_up() {
        new AlertDialog.Builder(getActivity()).setTitle("下班")//设置对话框标题
                .setMessage("确定要下班了吗")//设置显示的内容
                .setPositiveButton("是的",new DialogInterface.OnClickListener() {//添加确定按钮
                    @Override
                    public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
                        // TODO Auto-generated method stub
                        tvDaKa.setText("下班成功");
                        Toast.makeText(getActivity(),"下班成功",Toast.LENGTH_SHORT).show();
                    }
                }).setNegativeButton("不了",new DialogInterface.OnClickListener() {//添加返回按钮
            @Override
            public void onClick(DialogInterface dialog, int which) {//响应事件
                // TODO Auto-generated method stub
                Toast.makeText(getActivity(),"中国好同志", Toast.LENGTH_SHORT).show();
            }
        }).show();//在按键响应事件中显示此对话框
    }

    private void setLocationOption() {
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开GPS
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);// 设置定位模式
//        option.setCoorType("bd09ll"); // 返回的定位结果是百度经纬度,默认值gcj02
        option.setScanSpan(5000); // 设置发起定位请求的间隔时间为5000ms
        option.setIsNeedAddress(true); // 返回的定位结果包含地址信息
        option.setNeedDeviceDirect(true); // 返回的定位结果包含手机机头的方向

        locationClient.setLocOption(option);
    }

}
